package com.jasic.comnt.protocol;

import com.jasic.common.GlobalConstant;

/**
 * User: Jasic
 * Date: 12-12-22
 *
 * Base of socket data packet, every protocol should be extends it at this system
 */
public class MessageCommon {

    // current MessageCommon length
    public static int MSG_COMMON_LENGTH = 7;

    // Data -- head
    private byte header;

    // Data -- tail
    private byte tail;

    // Data -length
    private byte length;

    // Data -- command
    private byte cmd;

    // Who i am
    private byte question;

    // Is that you
    private byte answer;

    // Check number
    private byte checkNum;

    public MessageCommon(byte header, byte length, byte cmd, byte question, byte answer, byte tail) {
        this.header = header;
        this.tail = tail;
        this.length = length;
        this.cmd = cmd;
        this.question = question;
        this.answer = answer;
    }

    public MessageCommon(byte cmd, byte length, byte question, byte answer) {
        this.header = this.tail = GlobalConstant.ADD_CONNTDN_0x7e;
        this.cmd = cmd;
        this.length = length;
        this.question = question;
        this.answer = answer;
    }
    public MessageCommon(byte cmd, byte length) {
        this.header = this.tail = GlobalConstant.ADD_CONNTDN_0x7e;
        this.cmd = cmd;
        this.length = length;
        this.question = GlobalConstant.BUSINESS_SERVER;
        this.answer = GlobalConstant.PROTOCOL_SERVER;
    }

    /**
     * get MessageCommon length
     *
     * @return
     */
    public int length() {
        return 7;
    }

    public void setCheckNum(byte checkNum) {
        this.checkNum = checkNum;
    }

    public byte getCheckNum() {
        return checkNum;
    }

    public byte getHeader() {
        return header;
    }

    public byte getTail() {
        return tail;
    }

    public byte getLength() {
        return length;
    }

    public void setLength(byte length) {
        this.length = length;
    }

    public byte getCmd() {
        return cmd;
    }

    public byte getQuestion() {
        return question;
    }

    public byte getAnswer() {
        return answer;
    }
}
